<?php $this->_extends('_layouts/main_layout'); ?>

<?php $this->_block('title'); ?>
<?php
if (!empty($_SESSION['ga_title_full_reg']))
{
	echo $_SESSION['ga_title_full_reg'];
	unset($_SESSION['ga_title_full_reg']);
}
else
{
	echo 'Update Your Profile';
}
?>
<?php $this->_endblock(); ?>

<?php $this->_block('keywords');?>
<meta name="keywords" content="<?php echo $site['keywords']; ?>" />
<?php $this->_endblock();?>

<?php $this->_block('description');?>
<meta name="description" content="<?php echo $site['description']; ?>" />
<?php $this->_endblock();?>

<?php $this->_block('content'); ?>

<div class="mm help">
	<div class="topad">
		<?php if (!empty($user)) { ?>
		<?php echo str_replace('[[USER_ID]]', $user['id'], $site['ad_top']);?>
		<?php } ?>
	</div>
	<div class="clear" style="height: 10px"></div>
	<div class="left">
		<div class="title">Update Your Profile</div>
		<h3>Please provide a valid address and phone number so that we can send your prize.</h3>
		<form action="<?php echo url('user/profiling'); ?>" method="post">
			<ul class="errors">
			<?php 
				if(isset($errors))
				{
					foreach ($errors as $error)
					{
						echo "<li>$error</li>";
					}
				}
			?>
			</ul>	
			<ul class="infos">
			<?php 
				if(isset($infos))
				{
					foreach ($infos as $info)
					{
						echo "<li>$info</li>";
					}
				}
			?>
			</ul>				
			<div class="left">
				<div class="tr">
					<div class="lable left">Title</div>
					<div class="m left">
						<select name="gender">
							<option value="M" <?php echo isset($accountinfo['gender']) && $accountinfo['gender'] == 'M' ? 'selected="selected"' : '' ?>>Mr.</option>
							<option value="F" <?php echo isset($accountinfo['gender']) && $accountinfo['gender'] == 'F' ? 'selected="selected"' : '' ?>>Ms.</option>
						</select>
					</div>
					<div class="clear"></div>
				</div>
				<div class="tr">
					<div class="lable left">First Name</div>
					<div class="m left">
						<input class="inputtxt" name="firstname" id="firstname" value="<?php echo isset($accountinfo['firstname']) ? $accountinfo['firstname'] : ''; ?>"/>
					</div>
					<div class="clear"></div>
				</div>
				<div class="tr">
					<div class="lable left">Last Name</div>
					<div class="m left">
						<input class="inputtxt" name="lastname" id="lastname" value="<?php echo isset($accountinfo['lastname']) ? $accountinfo['lastname'] : ''; ?>"/>
					</div>
					<div class="clear"></div>
				</div>
				<div class="tr">
					<div class="lable left">Address</div>
					<div class="m left">
						<input class="inputtxt" type="text" name="address1" id="address" value="<?php echo isset($accountinfo['address1']) ? $accountinfo['address1'] : ''; ?>" />
					</div>
					<div class="clear"></div>
				</div>
				<div class="tr">
					<div class="lable left">Address 2</div>
					<div class="m left">
						<input class="inputtxt" type="text" name="address2" id="address2" value="<?php echo isset($accountinfo['address2']) ? $accountinfo['address2'] : ''; ?>" />
					</div>
					<div class="clear"></div>
				</div>
				<div class="tr">
					<div class="lable left">City/Town</div>
					<div class="m left">
						<input class="inputtxt" type="text" name="city" id="city" value="<?php echo isset($accountinfo['city']) ? $accountinfo['city'] : ''; ?>" />
					</div>
					<div class="clear"></div>
				</div><!--
				<div class="tr">
					<div class="lable left">State</div>
					<div class="m left">
						<select id="state" class="" name="state">
						<?php 
						
							$states = array(
								'AL' => 'Alabama',
								'AK' => 'Alaska',
								'AR' => 'Arkansas',
								'AE' => 'Armed Forces Africa/Europe/ME',
								'AA' => 'Armed Forces Americas',
								'AP' => 'Armed Forces Pacific',
								'AZ' => 'Arizona',
								'CA' => 'California',
								'CO' => 'Colorado',
								'CT' => 'Connecticut',
								'DE' => 'Delaware',
								'DC' => 'District of Columbia',
								'FL' => 'Florida',
								'GA' => 'Georgia',
								'GU' => 'Guam',
								'HI' => 'Hawaii',
								'ID' => 'Idaho',
								'IL' => 'Illinois',
								'IN' => 'Indiana',
								'IA' => 'Iowa',
								'KS' => 'Kansas',
								'KY' => 'Kentucky',
								'LA' => 'Louisiana',
								'ME' => 'Maine',
								'MD' => 'Maryland',
								'MA' => 'Massachusetts',
								'MI' => 'Michigan',
								'MN' => 'Minnesota',
								'MS' => 'Mississippi',
								'MO' => 'Missouri',
								'MT' => 'Montana',
								'NE' => 'Nebraska',
								'NV' => 'Nevada',
								'NH' => 'New Hampshire',
								'NJ' => 'New Jersey',
								'NM' => 'New Mexico',
								'NY' => 'New York',
								'NC' => 'North Carolina',
								'ND' => 'North Dakota',
								'OH' => 'Ohio',
								'OK' => 'Oklahoma',
								'OR' => 'Oregon',
								'PA' => 'Pennsylvania',
								'PR' => 'Puerto Rico',
								'RI' => 'Rhode Island',
								'SC' => 'South Carolina',
								'SD' => 'South Dakota',
								'TN' => 'Tennessee',
								'TX' => 'Texas',
								'UT' => 'Utah',
								'VI' => 'US Virgin Islands',
								'VT' => 'Vermont',
								'VA' => 'Virginia',
								'WA' => 'Washington',
								'WV' => 'West Virginia',
								'WI' => 'Wisconsin',
								'WY' => 'Wyoming',
							);
							
							foreach ($states as $k => $v) :
						?>
							<option value="<?php echo $k;?>" <?php echo (isset($accountinfo['state']) 
									&& $accountinfo['state'] == $k) ? 'selected="selected"' : ''; ?>><?php echo $v;?></option>
						<?php endforeach;?>
						</select>
					</div>
					<div class="clear"></div>
				</div>-->
				<div class="tr">
					<div class="lable left">Postal Code</div>
					<div class="m left">
						<input class="inputtxt" type="text" name="zipcode" id="zipcode" value="<?php echo isset($accountinfo['zipcode']) ? $accountinfo['zipcode'] : ''; ?>" maxlength="8"/>
					</div>
					<div class="error left">Invalid Postal Code, eg:DN16 9AA</div>
					<div class="clear"></div>
				</div>
				<div class="tr">
					<div class="lable left">Email</div>
					<div class="m left">
						<input class="inputtxt" name="email" id="email"
							value="<?php echo isset($accountinfo['email']) ? $accountinfo['email'] : ''; ?>" />
					</div>
					<div class="clear"></div>
				</div>
				<div class="tr">
					<div class="lable left">Telephone</div>
					<div class="m left">
						<input name="phone" id="phone" value="<?php echo isset($accountinfo['phone']) ? $accountinfo['phone'] : ''; ?>"/>
					</div>
					<div class="error left"></div>
					<div class="clear"></div>
				</div>
				<div class="tr">
					<div class="lable left">Birthday</div>
					<div class="m left">
						<span class="day">
							<select id="day" class="" name="birthDay">
								<option value="" selected="selected" label="Day">Day</option>
								<?php 
									$days = array(
											'01', '02', '03', '04', '05', '06', '07', '08', '09'
											,'10', '11', '12', '13', '14', '15', '16', '17', '18', '19'
											,'20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31'
									);
									foreach ($days as $day):
									
										if($accountinfo['birthDay'] == $day):
								?>
											<option value="<?php echo $day?>" selected="selected"><?php echo $day?></option>
										<?php else: ?>
											<option value="<?php echo $day?>"><?php echo $day?></option>
								<?php 
									endif;
									endforeach;
								?>
								</select>
						</span>
						<span class="month">
							<select id="month" class="" name="birthMonth">
								<option value=""  label="Month">Month</option>
								<option value="01" label="January" <?php echo (isset($accountinfo['birthMonth']) && $accountinfo['birthMonth'] == '01')? 'selected="selected"' : '';?>>January</option>
								<option value="02" label="February" <?php echo (isset($accountinfo['birthMonth']) && $accountinfo['birthMonth'] == '02')? 'selected="selected"' : '';?>>February</option>
								<option value="03" label="March" <?php echo (isset($accountinfo['birthMonth']) && $accountinfo['birthMonth'] == '03')? 'selected="selected"' : '';?>>March</option>
								<option value="04" label="April" <?php echo (isset($accountinfo['birthMonth']) && $accountinfo['birthMonth'] == '04')? 'selected="selected"' : '';?>>April</option>
								<option value="05" label="May" <?php echo (isset($accountinfo['birthMonth']) && $accountinfo['birthMonth'] == '05')? 'selected="selected"' : '';?>>May</option>
								<option value="06" label="June" <?php echo (isset($accountinfo['birthMonth']) && $accountinfo['birthMonth'] == '06')? 'selected="selected"' : '';?>>June</option>
								<option value="07" label="July" <?php echo (isset($accountinfo['birthMonth']) && $accountinfo['birthMonth'] == '07')? 'selected="selected"' : '';?>>July</option>
								<option value="08" label="August" <?php echo (isset($accountinfo['birthMonth']) && $accountinfo['birthMonth'] == '08')? 'selected="selected"' : '';?>>August</option>
								<option value="09" label="September" <?php echo (isset($accountinfo['birthMonth']) && $accountinfo['birthMonth'] == '09')? 'selected="selected"' : '';?>>September</option>
								<option value="10" label="October" <?php echo (isset($accountinfo['birthMonth']) && $accountinfo['birthMonth'] == '10')? 'selected="selected"' : '';?>>October</option>
								<option value="11" label="November" <?php echo (isset($accountinfo['birthMonth']) && $accountinfo['birthMonth'] == '11')? 'selected="selected"' : '';?>>November</option>
								<option value="12" label="December" <?php echo (isset($accountinfo['birthMonth']) && $accountinfo['birthMonth'] == '12')? 'selected="selected"' : '';?>>December</option>
							</select>
						</span>
						<span class="year">
							<select id="year" class="" name="birthYear">
								<option value="" selected="selected" label="Year">Year</option>
								<?php 
									for ($i = date('Y')*1-18; $i >= date('Y')*1-100 ; $i--) :
								?>
									<option value="<?php echo $i; ?>" <?php echo (isset($accountinfo['birthYear']) && intval($accountinfo['birthYear']) == $i) ? 'selected="selected"' : '';?>><?php echo $i;?></option>
								<?php endfor;?>
							</select>
						</span>
					</div>
					
					<div class="clear"></div>
				</div>
				
				
				
				
				<?php if (empty($accountinfo['optin_edu']) || $accountinfo['optin_edu'] == '0') { ?>
<!-- 				<div class="tr" style="line-height:18px;">
						<div class="lable left" style="height:40px;"></div> 
						<div>
							<input type="checkbox" name="optin_edu" id="optin_edu" value="1" />
							<label for="optin_edu">Sign up for Eversave Coupons & Savings today for email with FREE coupons and samples from top brand names plus recipes, sweepstakes and much more!</label> 
							<div class="clear"></div>
						</div>
					</div>
-->
				<?php } ?>
			
				<?php if (empty($accountinfo['optin_sj']) || $accountinfo['optin_sj'] == '0') { ?>
<!-- 				<div class="tr" style="line-height:18px;">
						<div class="lable left" style="height:40px;"></div> 
						<div>
							<input type="checkbox" name="optin_sj" id="optin_sj" value="1" />
							<label for="optin_sj">Get Paid to Review products online for cash and rewards with Shopping Jobs.com, It’s free to Join!</label> 
							<div class="clear"></div>
						</div>
					</div>
-->
				<?php } ?>
				
				
				
				
				
				<div class="tr">
					<div class="lable left"></div>
					<div class="m left save">
						<input type="image"
							src="<?php echo $img_url;?>saveprofile.png" alt=""
									name="submit" width="208" height="51" id="submit"/>
					</div>
					<div class="clear"></div>
				</div>
			</div>
			<span class="left">
				<?php if(isset($user) && empty($user['address1'])): ?>
					<img alt="" src="<?php echo $img_url;?>clicktocomplete2_2.png" />
				<?php endif;?>
			</span>
		</form>
		
	</div>
	<div class="right rightad">
		<?php $this->_element('rightad'); ?>
	</div>
	<div class="clear" style="height: 20px;"></div>
	<div class="bottomad">
		<?php echo $site['ad_bottom']; ?>
	</div>
</div>
<div class="mb"></div>
<script type="text/javascript">
	
	$(function(){		
		$('#submit').click(function(){
			var reg=/^[a-zA-Z\d\s]{5,8}$/;
			if(!reg.test($('#zipcode').val())){
				$('#zipcode').parent().next().show();
				return false;
			}

			var phone = $('#phone').val();
			var telNumberErrorNo = 0;
			var telNumberErrors = new Array ();
			telNumberErrors[0] = "Valid UK telephone number";
			telNumberErrors[1] = "Telephone number not provided";
			telNumberErrors[2] = "UK telephone number without the country code, please";
			telNumberErrors[3] = "UK telephone numbers should contain 10 or 11 digits except the leading zero";
			telNumberErrors[4] = "The telephone number should start with a 0";
			telNumberErrors[5] = "The telephone number is either invalid or inappropriate";
			telNumberErrorNo = checkUKTelephone(phone);
			if($.inArray(telNumberErrorNo, [1,2,3,4,5]) >= 0){
				$('#phone').parent().next().html('Invalid Number, ' + telNumberErrors[telNumberErrorNo]).show();
				return false;
			}
			return true;
		});
		$('#zipcode').focus(function(){
				$(this).parent().next().hide();
			}
		);
		$('.inputphone').each(function(){
			$(this).focus(function(){
				$(this).parent().next().hide();
			});
		});
	});

	function checkUKTelephone (telephoneNumber) {
		// Convert into a string and check that we were provided with something
		var telnum = telephoneNumber + " ";
		if (telnum.length == 1) {
			telNumberErrorNo = 1;
			return telNumberErrorNo;
		}
		telnum.length = telnum.length - 1;
		// Don't allow country codes to be included (assumes a leading "+")
		var exp = /^(\+)[\s]*(.*)$/;
		if (exp.test(telnum) == true) {
			telNumberErrorNo = 2;
			return telNumberErrorNo;
		}
		// Remove spaces from the telephone number to help validation
		while (telnum.indexOf(" ")!= -1) {
			telnum = telnum.slice (0,telnum.indexOf(" ")) + telnum.slice (telnum.indexOf(" ")+1)
		}
		// Remove hyphens from the telephone number to help validation
		while (telnum.indexOf("-")!= -1) {
			telnum = telnum.slice (0,telnum.indexOf("-")) + telnum.slice (telnum.indexOf("-")+1)
		}
		// Now check that all the characters are digits
		exp = /^[0-9]{10,12}$/;
		if (exp.test(telnum) != true) {
			telNumberErrorNo = 3;
			return telNumberErrorNo;
		}
		// Now check that the first digit is 0
		exp = /^0[0-9]{9,11}$/;
		if (exp.test(telnum) != true) {
			telNumberErrorNo = 4;
			return telNumberErrorNo;
		}
		// Disallow numbers allocated for dramas.
		// Array holds the regular expressions for the drama telephone numbers
		var tnexp = new Array ();
		tnexp.push (/^(0113|0114|0115|0116|0117|0118|0121|0131|0141|0151|0161)(4960)[0-9]{3}$/);
		tnexp.push (/^02079460[0-9]{3}$/);
		tnexp.push (/^01914980[0-9]{3}$/);
		tnexp.push (/^02890180[0-9]{3}$/);
		tnexp.push (/^02920180[0-9]{3}$/);
		tnexp.push (/^01632960[0-9]{3}$/);
		tnexp.push (/^07700900[0-9]{3}$/);
		tnexp.push (/^08081570[0-9]{3}$/);
		tnexp.push (/^09098790[0-9]{3}$/);
		tnexp.push (/^03069990[0-9]{3}$/);
		for (var i=0; i<tnexp.length; i++) {
			if ( tnexp[i].test(telnum) ) {
				telNumberErrorNo = 5;
				return telNumberErrorNo;
			}
		}
		// Finally check that the telephone number is appropriate.
		exp = (/^(01|02|03|05|070|071|072|073|074|075|07624|077|078|079)[0-9]+$/);
		if (exp.test(telnum) != true) {
			telNumberErrorNo = 5;
			return telNumberErrorNo;
		}
		// Telephone number seems to be valid - return the stripped telehone number
		return telnum;
	}
	
	<?php if(isset($_SESSION['redirect_url'])):?>
		window.open('<?php echo url('user/adflow');?>');
	<?php endif;?>	
	
</script>
<?php $this->_endblock(); ?>